//
//  SYNewAlerView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/12.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYNewAlerView.h"


@interface SYNewAlerView ()

@property (strong, nonatomic) SYNewAlerView *alerView;
@property (strong, nonatomic) UIView *contBgView;
@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UILabel *titleLab;
@property (strong, nonatomic) UITextField *textField;//输入框
@property (strong, nonatomic) UIView *fgxView;
@property (strong, nonatomic) UIView *sfgxView;
@property (strong, nonatomic) UIButton *quxiaoBtn;
@property (strong, nonatomic) UIButton *quedingBtn;


@end


@implementation SYNewAlerView

- (instancetype)init {
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        [self initSubView];
    }
    return self;
}


- (void)showAler:(SYNewAlerView *)alerView titleName:(NSString *)title textFielPlo:(NSString *)plo {
    _alerView = alerView;
    self.titleLab.text = title;
    self.textField.placeholder = plo;
    UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
     [window addSubview:alerView];
    
    [UIView animateWithDuration:0.25 animations:^{
        alerView.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
        
    }];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
//    [_alerView removeFromSuperview];
}

- (void)initSubView {
    [self addSubview:self.contBgView];
    [self.contBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self);
    }];
    
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(60);
        make.centerY.equalTo(self.mas_centerY).offset(-80);
        make.width.mas_offset(300);
        make.height.mas_offset(150);
    }];
    [self.bgView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.top.equalTo(self.bgView.mas_top).offset(15);
    }];
    //输入
    [self.bgView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.top.equalTo(self.titleLab.mas_bottom).offset(13);
        make.width.mas_equalTo(235);
        make.height.mas_equalTo(35);
    }];
    //分割线
    [self.bgView addSubview:self.fgxView];
    [self.fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.bgView);
        make.top.equalTo(self.textField.mas_bottom).offset(16);
        make.height.mas_equalTo(.5);
    }];
    //分割线
    [self.bgView addSubview:self.sfgxView];
    [self.sfgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fgxView.mas_bottom);
        make.width.mas_equalTo(1);
        make.bottom.equalTo(self.bgView.mas_bottom);
        make.centerX.equalTo(self.bgView.mas_centerX);
    }];
    //取消
    [self.bgView addSubview:self.quxiaoBtn];
    [self.quxiaoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.top.equalTo(self.fgxView.mas_bottom);
        make.left.bottom.equalTo(self.bgView);
        make.right.equalTo(self.sfgxView.mas_left);
        make.height.mas_equalTo(43);
    }];
    [self.bgView addSubview:self.quedingBtn];
    
    [self.quedingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.bgView);
        make.height.mas_equalTo(43);
        make.width.mas_equalTo(140);
    }];
    

}

- (UIView *)contBgView {
    if (!_contBgView) {
        _contBgView = [[UIView alloc] init];
        _contBgView.backgroundColor = [UIColor blackColor];
        _contBgView.backgroundColor = TITLECOLOR;
        _contBgView.alpha = 0.3;
    }
    return _contBgView;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.masksToBounds = YES;
        _bgView.layer.cornerRadius = 10;
    }
    return _bgView;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel titleColour:TITLECOLOR
                              titleFount:16
                                pingfang:@"PingFang-SC-Medium"
                               alignment:NSTextAlignmentCenter
                               titleLine:1];
        _titleLab.text = @"新建文件夹";
    }
    return _titleLab;
}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.placeholder = @" 文件夹名称";
        _textField.layer.borderWidth = 1;
        _textField.layer.borderColor = [UIColor colorWithHexString:@"#CCCCCC"].CGColor;
    }
    return _textField;
}
- (UIView *)fgxView {
    if (!_fgxView) {
        _fgxView = [[UIView alloc] init];
        _fgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    }
    return _fgxView;
}
- (UIView *)sfgxView {
    if (!_sfgxView) {
        _sfgxView = [[UIView alloc] init];
        _sfgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    }
    return _sfgxView;
}
- (UIButton *)quxiaoBtn {
    if (!_quxiaoBtn) {
        _quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_quxiaoBtn setTitleColor:[UIColor colorWithHexString:@"#20B097"] forState:UIControlStateNormal];
        [_quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_quxiaoBtn addTarget:self action:@selector(quxiaoBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
         _quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _quxiaoBtn;
}
- (UIButton *)quedingBtn {
    if (!_quedingBtn) {
        _quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_quedingBtn setTitleColor:[UIColor colorWithHexString:@"#20B097"] forState:UIControlStateNormal];
        [_quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_quedingBtn addTarget:self action:@selector(quedingBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _quedingBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    }
    return _quedingBtn;
}
- (void)quxiaoBtnClick {
    [_alerView removeFromSuperview];
}
- (void)quedingBtnClick {
    if (self.textField.text.length == 0) {
        
        return;
    }
    if (self.block) {
        self.block(self.textField.text);
    }
    [_alerView removeFromSuperview];
}


@end























